/*
 * @Author: jh
 * 数组添加、去重
 * 数组的tag删除
 */

export default {
    data() {
        return {
        }
    },
    methods: {
        /*数组的tag删除
        * tag 标签对象
        * checkedList 选中的下拉项
        * */
        handleCloseTag(tag,checkedList,callBack) {
             let index = checkedList.indexOf(tag)
             checkedList.splice(index, 1);
            if (callBack) {
                callBack(checkedList.indexOf(tag))
            }
            //刷新dom
            checkedList = checkedList.filter(function (item) {
                return item
            })
        },
        /* 数组添加、去重
         * id 选中的项的value
         * checkedList 选中的下拉项列表
         * allList 所有的下拉项列表
         * color 选中的变色 boolean
         * */
        addToArr(id,checkedList,allList,color,callBack,callBack2) {
            //console.log(id,"员工id")
            let flag = false;
            for (let item of checkedList) {
                if (item.id === id) {
                    flag = true;
                    break;
                }
            }
            if (!flag) {
                for (let item of allList) {
                    if (item.id === id) {
                        //让选中的置灰
                        //item.disabled = true
                       // checkedList.splice(0, 0, item);
                        if (callBack2) {
                            callBack2()
                        }
                        checkedList.push(item);
                    }
                }
            }
            //设置颜色
            if (color) {
                let curentTagIndex = 0
                checkedList.map((tag,index)=>{
                    if (id === tag.id) {
                        tag.color = 'danger';
                        curentTagIndex = index
                        if (callBack) {
                            callBack(id,curentTagIndex,true)
                        }
                    } else {
                        tag.color = '';
                    }
                })
            }
            //this.searchStaff=''
        },
    }
}
